package com.pxmeta.admin.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.google.common.collect.Maps;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.file.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@RestController
@Api(value = "文件管理",tags = "文件")
@RequestMapping(value = "/file")
@CrossOrigin
@RequiredArgsConstructor
public class FileController {

    private final OssService ossService;

    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file){
        String url = ossService.updateFile(file);
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("url", url);
        return AjaxResult.success(map);
    }

}
